<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>学生信息管理</title>
<link rel="stylesheet" type="text/css" href="jquery-easyui-1.5.5.4/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="jquery-easyui-1.5.5.4/themes/icon.css">
<script type="text/javascript" src="jquery-easyui-1.5.5.4/jquery.min.js"></script>
<script type="text/javascript" src="jquery-easyui-1.5.5.4/jquery.easyui.min.js"></script>
<script type="text/javascript" src="jquery-easyui-1.5.5.4/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">
	function searchStudent(){
		$('#dg').datagrid('load',{
			stuNo:$('#search_stuNo').val(),
			stuName:$('#search_stuName').val(),
			sex:$('#search_sex').combobox("getValue"),
			bbirthday:$('#search_bbirthday').datebox("getValue"),
			ebirthday:$('#search_ebirthday').datebox("getValue"),
			gradeId:$('#search_gradeId').combobox("getValue")
		});
	}
	
	
	function deleteStudent(){
		var selectRows = $('#dg').datagrid('getSelections');
		if(selectRows.length == 0){
			$.messager.alert("系统提示","请选择要删除的数据！");
		}
		var strIds = [];
		for(i=0;i<selectRows.length;i++){
			strIds.push(selectRows[i].stuId);
		}
		var ids = strIds.join(",");
		$.messager.confirm("系统提示","您确认要删除这<font color=red>"+selectRows.length+"</font>条数据吗？",function(r){
			if(r){
				$.post("studentdelete",{delIds:ids},function(result){
					if(result.success){
						$.messager.alert("系统提示","您已经成功删除了<font color=red>"+result.delNum+"</font>条数据！");
						$('#dg').datagrid('reload'); 
					}else{
						$.messager.alert("系统提示",result.errorMsg);
					}
				},"json");
			}		
		});
	}
	function openStudentAddDialog(){
		$("#dlg").dialog("open").dialog("setTitle","添加学生信息");
		url="studentsave";
	}
	function closeStudentDialog(){
		$("#dlg").dialog("close");
		resetValue();
	}
	
	function resetValue(){
		$("#stuNo").val("");
		$("#stuName").val("");
		$("#sex").combobox("setValue","");
		$("#birthday").datebox("setValue","");
		$("#gradeId").combobox("setValue","");
		$("#email").val("");
		$("#stuDesc").val("");
	}
	function saveStudent(){
		$("#fm").form("submit",{
			url:url,
			onSubmit:function(){
				if($("#sex").combobox("getValue")==""){
					$.messager.alert("系统提示","请选择学生性别！");
					return false;
				}
				if($("#gradeId").combobox("getValue")==""){
					$.messager.alert("系统提示","请选择学生班级！");
					return false;
				}
				return $(this).form("validate");
			},
			success:function(result){
				if(result.errorMsg){
					$.messager.alert("系统提示",result.errorMsg);
					return;
				}else{
					$.messager.alert("系统提示","保存成功！");
					resetValue();
					$("#dlg").dialog("close");
					$("#dg").datagrid('reload'); 
				}
			}
		});
	}
	
	function openStudentModifyDialog(){
		var selectRows = $('#dg').datagrid('getSelections');
		if(selectRows.length != 1){
			$.messager.alert("系统提示","请选择一条要修改的数据！");
			return;
		}
		$("#dlg").dialog("open").dialog("setTitle","修改学生信息");
		var row = selectRows[0];
		$("#fm").form("load",row);
		url="studentsave?stuId="+row.stuId;
	}
	
</script>
</head>
<body style="margin:5px">
<table class="easyui-datagrid" id="dg" title="学生信息" fitColumns="true" pagination="true" rownumbers="true" fit="true" url="studentlist" toolbar="#tb">
	<thead>
		<tr>
			<th field="cb" checkbox="true"></th>
			<th field="stuId" width="100">学生序号</th>
			<th field="stuNo" width="100">学生学号</th>
			<th field="stuName" width="100">学生姓名</th>
			<th field="sex" width="100">学生年龄</th>
			<th field="birthday" width="100">出生日期</th>
			<th field="gradeName" width="100">学生班级</th>
			<th field="email" width="150">学生邮箱</th>
			<th field="stuDesc" width="250">学生描述</th>
		</tr>
	</thead>
</table>

<div id="tb">
	<div>
		<a href="javascript:openStudentAddDialog()" class="easyui-linkbutton" plain="true" iconCls="icon-add">添加</a>
		<a href="javascript:openStudentModifyDialog()" class="easyui-linkbutton" plain="true" iconCls="icon-edit">修改</a>
		<a href="javascript:deleteStudent()" class="easyui-linkbutton" plain="true" iconCls="icon-remove">删除</a>
	</div>
	<div>&nbsp;学生学号：&nbsp;<input type="text" name="search_stuNo" id="search_stuNo" size="10"/>
	&nbsp;学生姓名：&nbsp;<input type="text" name="search_stuName" id="search_stuName" size="10"/>
	&nbsp;学生性别：&nbsp;<select class="easyui-combobox" name="search_sex" id="search_sex" editable="false" panelHeight="auto" >
		<option value="">请选择</option>
		<option value="男">男</option>
		<option value="女">女</option>
	</select>
	&nbsp;出生日期：&nbsp;<input class="easyui-datebox" id="search_bbirthday" name="search_bbirthday" editable="false" size="15"/>-><input class="easyui-datebox" id="search_ebirthday" name="search_ebirthday" editable="false" size="15"/>
	&nbsp;所属班级：&nbsp;<input class="easyui-combobox" id="search_gradeId" name="search_gradeId" editable="false" panelHeight="auto" size="15" data-options="editable:false,valueField:'id',textField:'gradeName',url:'gradecombolist'"/>
	<a href="javascript:searchStudent()" class="easyui-linkbutton" plain="true" iconCls="icon-search">搜索</a></div>
	<div id="dlg" class="easyui-dialog" style="width:550px;height:400px;padding:10px 20px" closed="true" buttons="#dlg-buttons">
		<form id="fm" method="post">
		<table>
				<tr>
					<td>学生学号：</td>
					<td><input type="text" id="stuNo" name="stuNo" class="easyui-validatebox" required="true"/></td>
					<td>学生姓名：</td>
					<td><input type="text" id="stuName" name="stuName" class="easyui-validatebox" required="true"/></td>
				</tr>
				<tr>
					<td>学生性别：</td>
					<td><select class="easyui-combobox" name="sex" id="sex" editable="false" panelHeight="auto" style="width:147px;">
						<option value="">请选择</option>
						<option value="男">男</option>
						<option value="女">女</option>
					</select></td>
					<td>出生日期：</td>
					<td><input class="easyui-datebox" id="birthday" required="true" name="birthday" editable="false" /></td>
				</tr>
				<tr>
					<td>学生班级：</td>
					<td><input class="easyui-combobox" id="gradeId" name="gradeId" editable="false" panelHeight="auto" data-options="editable:false,valueField:'id',textField:'gradeName',url:'gradecombolist'"/></td>
					<td>Email：</td>
					<td><input type="text" id="email" name="email" class="easyui-validatebox" required="true" validType="email"/></td>
				</tr>
				<tr>
					<td valign="top">学生描述：</td>
					<td colspan="3"><textarea rows="8" cols="42" id="stuDesc" name="stuDesc"></textarea></td>
				</tr>
		</table>
		</form>
	</div>
	<div id="dlg-buttons">
		<a href="javascript:saveStudent()" class="easyui-linkbutton" iconCls="icon-ok">保存</a>
		<a href="javascript:closeStudentDialog()" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
	</div>
</div>
</body>
</html>